<template>
	<div>
		<van-swipe :autoplay="3000">
			<van-swipe-item v-for="(img,i) in shareimgls" :key="i">
				<van-image width="100%" height="300px" :src="img"></van-image>
				<!-- <img width="100%" :src="img"/> -->
			</van-swipe-item>
		</van-swipe>
		<h3 style="margin-bottom: 5px;">{{this.shareList.title}}</h3>
		<div style="display: flex;">
			<p style="width: 20%; ">{{this.shareList.uname}}</p>
			<p style="display: inline-block;">{{this.shareList.creattime}}</p>
		</div>
		<p style="text-align: left; width: 90%;  margin: 10px; text-indent: 1.5em;
      border: 1px solid; padding: 5px; border-radius: 10px;
     line-height: 1.5rem;">{{this.shareList.note}}</p>
		<van-card v-if="goods" :price="formatPrice(goods.price)" :desc="goods.spec" :title="goods.goodname"
			:thumb="goods.imgurl" @click="todetail(goods.goodid)">
		</van-card>
	</div>
</template>

<script>
	import {
		CellGroup
	} from "vant";
	import request, {
		getUrl
	} from "../../utils/request2";
	export default {
		data() {
			return {
				shareid: -1,
				shareList: [],
				shareimgls: [],
				goods: null
			}
		},
		created() {
			this.shareid = this.$route.query.shareid;
			console.log("Share ID:", this.shareid);

			// 获取商品详情
			request({
					url: getUrl("Share/getShareDetail"),
					method: "get",
					params: {
						id: this.shareid
					}
				})
				.then(res => {
					console.log("Share Detail Response:", res.data);
					this.shareList = res.data.data;
					this.shareimgls = res.data.data.imgurl;
					console.log("Share List:", this.shareList);

					// 获取商品列表
					return request({
						url: getUrl("Goods/getGoodsListById"),
						method: "get",
						params: {
							goodsid: this.shareList.goodsid
						}
					});
				})
				.then(res => {
					console.log("Goods List Response:", res.data);
					this.goods = res.data.data;
					console.log("Goods:", this.goods);
				})
				.catch(error => {
					console.error("Network Error:", error);
					showDlg('错误提醒', '网络错误！');
				});
		},
		methods: {
			formatPrice(price) { //格式化价格
				return (price * 100 / 100).toFixed(2);
			},
			todetail(goodsid) { //跳转到制定商品详情
				this.$router.push("/goodsdetail?goodsid=" + goodsid);
			}
		}
	}
</script>

<style>
	.van-swipe-item {
		text-align: center;
	}
</style>
